package io.zhiller.koinbasictemplate.di.viewmodel

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import io.zhiller.koinbasictemplate.di.repo.BasicRepoImpl
import io.zhiller.koinbasictemplate.di.states.BasicStates
import kotlinx.coroutines.launch


class BasicVM(
  private val basicRepo: BasicRepoImpl
) : ViewModel() {
  val basicStates: BasicStates = BasicStates()

  init {
    initStates()
  }

  private fun initStates() {
    basicStates.name = basicRepo.getDataWithParam(0).name
  }

  fun updateDataWithIndex(index: Int) = viewModelScope.launch {
    basicStates.name = basicRepo.getDataWithParam(index).name
  }

  fun getDataWithIndex(index: Int) = basicRepo.getDataWithParam(index)
}
